<template>
<table
    class="gas-cp-container"
    border="1">
    <tr class="top-container">
        <td class="left">
            天然气-组分特征-重烃 基础数据
        </td>
        <td class="right">
            当前报告
        </td>
    </tr>
    <tr class="content-container">
        <td class="left">
            <div class="container">
                <div class="chart">
                    <MyChart
                        ref="MyChart">
                    </MyChart>
                </div>
            </div>
        </td>
        <td class="right">
            <div class="chart">
                <MyChart
                    ref="MyChart1">
                </MyChart>
            </div>
        </td>
    </tr>
    <tr class="bottom-container" v-if="false">
        <td
            colspan="2"
            class="container">
            低熟油型气
        </td>
    </tr>
</table>
</template>
<script>
/*
 天然气-组分特征-重烃展示页面
 */
import {randomColor} from "@/common/ColorTools";
import {computedRem} from "@/common/OtherTools";
import {isEmptyObject} from '@/common/OtherTools';
import MyChart from '@/components/MyChart';
export default {
    components:{MyChart},
    props:{
        currentReport:{  //当前选择的报告
            type:Object,
            default:()=>{
                return {};
            },
        },
        fontColor:{
            type:String,
            default:'',
        },
        borderColor:{
            type:String,
            default:'',
        },
        chartBorderColor:{
            type:String,
            default:'',
        },
    },
    data() {
        this.nameConfigMap = {};  //颜色列表(保持颜色一致)
        return {
        };
    },
    watch:{
        currentReport(){
            this.getReportData();
        },
    },
    mounted(){
        this.getBaseData();
    },
    methods:{
        computConfig(data = []){  //计算配置
            data = data || [];
            data.forEach(item=>{
                this.nameConfigMap[item.horizon] = this.nameConfigMap[item.horizon] || {
                    color:randomColor(),
                };
            });
        },
        computedRem,
        getBaseData(){  //获取基础数据
            this.$Service.post(
                this.$Api.findHydrocarbon,
                {
                    "isbasic":1,
                },
            ).then(data => {
                this.computConfig(data.data);
                let target = this.$refs.MyChart;
                this.drawChart({target,data:data.data});
            }).catch(() => {
                return;
            });
        },
        getReportData(){  //获取报告数据
            let target = this.$refs.MyChart1;
            if(isEmptyObject(this.currentReport)){
                this.drawChart({target,data:[]});
                return;
            }
            this.$Service.post(
                this.$Api.findHydrocarbon,
                {
                    "reportType":this.currentReport.reportType,
                    "reportNo":this.currentReport.reportNo,
                },
            ).then(data => {
                this.computConfig(data.data);
                this.drawChart({target,data:data.data});
            }).catch(() => {
                this.drawChart({target,data:[]});
                return;
            });
        },
        drawChart({target,data=[]}){  //绘制表格
            let rem = computedRem();
            var option = {
                grid: {
                    left: '15%',
                    right: '5%',
                    top: '10%',
                    bottom: '10%',
                },
                tooltip: {
                    trigger: 'item',
                    formatter: params=>{
                        return `${params.name}:${params.value}`;
                    },
                },
                xAxis: {
                    type: 'category',
                    data: data.map(item=>{
                        return item.horizon;
                    }),
                    nameTextStyle:{
                        fontWeight:'bold',
                        fontSize:1*rem,
                    },
                    splitArea: {
                        show: false,
                    },
                    splitLine: {
                        show: false,
                    },
                    axisLine: {
                        show:true,
                        lineStyle: {
                            color:this.fontColor,
                        },
                        onZero:false,
                    },
                    axisLabel:{  //x轴的标签设置
                        show:true,
                        lineStyle: {
                            color:this.fontColor,
                        },
                    },
                },
                yAxis: {
                    type: 'value',
                    min:0,
                    max:12,
                    nameTextStyle:{
                        fontWeight:'bold',
                        fontSize:18,
                    },
                    splitArea: {
                        show: false,
                    },
                    axisLine: {
                        show:true,
                        lineStyle: {
                            color:this.fontColor,
                        },
                        onZero:false,
                    },
                    splitLine: {//分割线配置
                        show:true,
                        lineStyle: {
                            color: this.chartBorderColor,
                        }
                    },
                },
                series: [
                    {
                        data:data.map(item=>{
                            return {
                                value:item.ethane,
                                itemStyle:{
                                    color:this.nameConfigMap[item.horizon].color,
                                },
                                label: {
                                    show: true, //开启显示
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: this.fontColor,
                                        fontSize: 14,
                                        fontWeight: 600
                                    }
                                }
                            };
                        }),
                        barWidth : 30,//柱图宽度
                        type: 'bar',
                    }
                ],
            };
            target && target.setOption(option);
        },
    },
};
</script>
<style scoped lang="scss">
.gas-cp-container{
    width: 100%;
    height: fit-content;
    text-align: left;
    color: var(--font-color);
    box-sizing: border-box;
    border-collapse: collapse;
    border-color: var(--border-color);
    border: 1px solid var(--border-color);
    table-layout:fixed;
    >tr{
        >td{
            &:last-child{
                width: 50%;
            }
        }
    }
    >.top-container{
        >td{
            font-size: 1.5rem;
            font-weight: bold;
            padding: 1rem;
            box-sizing: border-box;
            line-height: 1;
            box-sizing: border-box;
        }
    }
    >.content-container{
        >.left{
            >.container{
                display: grid;
                grid-template-columns: 1fr;
                >.chart{
                    width: 100%;
                    height: 30rem;
                }
                >.base-data{
                    padding: 1rem 1rem 1rem 0;
                    box-sizing: border-box;
                    width: 100%;
                    text-align: center;
                    display: grid;
                    grid-gap: 1rem;
                    height: fit-content;
                    >.base-data-title{
                        font-size: 1.5rem;
                    }
                    >table{
                        width: 100%;
                        height: fit-content;
                        border-collapse: collapse;
                        border-color: #0f4b78;
                        border: 1px solid #0f4b78;
                        td,th{
                            padding: 1rem 0.5rem;
                            text-align: center;
                            font-size: 1rem;
                            box-sizing: border-box;
                        }
                        th{
                            font-size: 1rem;
                            font-weight: bold;
                        }
                        .cols2,.cols4,.cols6{
                            width: 50%;
                        }
                    }
                }
            }
        }
        >.right{
            >.chart{
                width: 100%;
                height: 30rem;
            }
        }
    }
    >.bottom-container{
        >.container{
            padding: 1.5rem 1rem;
            font-size: 1.5rem;
            color: #99a9bf;
            box-sizing: border-box;
            span{
                font-size: 1.7rem;
                color: var(--font-color);
            }
            .data{
                font-size: 2rem;
                color: #00c57a;
                font-weight: bold;
            }
        }
    }
}
</style>
